﻿using MudBlazor.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MXERP.Blazor.Components
{
    public partial class Ellipsis : MudComponentBase
    {
        [Parameter]
        public RenderFragment? ChildContent { get; set; }

        public ElementReference EllipsisRef { get; set; }

        public ElementReference EllipsisChildRef { get; set; }

        public bool _isShowTooltip;

        protected string ClassName => new CssBuilder("md-ellipsis")
            .AddClass(Class)
            .Build();

        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);
            if (firstRender)
            {
                var ellipsisRect = await EllipsisRef.MudGetBoundingClientRectAsync();
                var ellipsisChildRect = await EllipsisChildRef.MudGetBoundingClientRectAsync();
                if (ellipsisRect.Width != ellipsisChildRect.Width)
                {
                    _isShowTooltip = true;
                }
                StateHasChanged();
            }
        }
    }
}
